# Untitled 3.py
# Created by hello on 2021/1/25.
import requests
import time
from bs4 import BeautifulSoup

class Site(object):
    def __init__(self, name, url,kw):
        self.name = name
        self.url = url
        self.kw = kw 

    def run_word(self):
        url = self.url+'/w/'+self.kw
        headers = {
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36',
        }
        ret = requests.get(url=url,headers=headers)
        print(ret.status_code)
        if(ret.status_code==200):
            soup=BeautifulSoup(ret.text,'html.parser')
            div = soup.find('div',class_='trans-container')
            ul = div.find_all('li')
            ll=[]
            for li in ul:
                print(type(li),li)
                ll.append(li.string)
            return ll
        else:
            print("NO RESULT")
        return url

	# def print_score(self):
	# 	print('%s: %s'  % (self.name,self.__score))
		
	# def get_grade(self):
	# 	if self.score >= 90:
	# 		return 'A'
	# 	elif self.score >= 60:
	# 		return 'B'
	# 	else:
	# 		return 'C'
	
	# def get_score(self):
	# 	return self.__score
		
	# 相当于OC总的description
# 	def __str__(self):
# 		return 'Student object (name: %s)' % self.name
# bart = Student('Bart Simpson', 59)
# lisa = Student('Lisa Simpson', 87)

# print('bart.name = ', bart.name)
# #print('bart.score= ', bart.score)
# bart.print_score()
# print('bart.get_score() =', bart.get_score())
# print(bart)
if __name__== "__main__":
    wy = Site("网易",'https://youdao.com','main')
    ret = wy.run_word()
    print(ret)
